<?php

namespace App\Components\Goods\Commands;

use App\Components\Goods\Models\SearchRecord;
use App\Modules\Good\Models\Good;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;

class Off extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'goods:off';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '下架活动结束的商品';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        Good::query()
            ->where('status', Good::STATUE_ON)
            ->where('end_time', '<', now()->toDateString())
            ->orderBy('end_time')
            ->each(function ($item) {
                $item->status = Good::STATUE_OFF;
                $item->save();
            });
    }
}
